<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class LiveTypeController extends AdminbaseController{
	
	function _initialize() {
		parent::_initialize();
	}
	
	function index(){
		$category = I("post.category", -1);
		$result = $this->curl_http(C('video_url').'live_type/getList?token='.$_SESSION["TOKEN"], 'category='.$category);
		$this->assign("data", $result['ReturnData']);
		$this->assign("category", $category);
		$this->display();
	}
	
	
	function add(){
		$this->display();
	}
	
	function add_post(){
		$name = I("post.name", "");
		if(empty($name)){
			return $this->error("类型名称不能为空！");
		}
		$category = I("post.category", 1);
		$result = $this->curl_http(C('video_url').'live_type/add?token='.$_SESSION["TOKEN"], 'name='.$name.'&category='.$category);
		if($result['Success']){
			$this->success("添加成功！", U("Admin/LiveType/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	function edit(){
		$this->assign("typeId", I("get.typeId", 0));
		$this->assign("name", I("get.name", ""));
		$this->assign("category", I("get.category", 1));
		$this->display();
	}
	
	function edit_post(){
		$name = I("post.name", "");
		if(empty($name)){
			return $this->error("类型名称不能为空！");
		}
		$typeId = I("post.typeId", 0);
		$category = I("post.category", 1);
		$result = $this->curl_http(C('video_url').'live_type/update?token='.$_SESSION["TOKEN"], 'name='.$name.'&typeId='.$typeId.'&category='.$category);
		if($result['Success']){
			$this->success("修改成功！", U("Admin/LiveType/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	function delete(){
		$typeId = I("get.typeId", 0);
		$result = $this->curl_http(C('video_url').'live_type/delete?token='.$_SESSION["TOKEN"], 'typeId='.$typeId);
		if($result['Success']){
			$this->success("修改成功！", U("Admin/LiveType/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
}